<?php
class DealUserVouchersController extends AppController
{
    var $name = 'DealUserVouchers';
    
    function beforeFilter()
    {
        //Configure::write('debug',2);
        //$this->Auth->allow('*');
        parent::beforeFilter();
    }
    
    function admin_delete($id = null)
    {
        if (is_null($id)) {
            $this->cakeError('error404');
        }
        
        if ($this->DealUserVoucher->del($id) && $this->DealUserVoucher->DealUser->del($id)) {
            $this->DealUserVoucher->DealUser->DealUserCoupon->deleteAll(array(
                'DealUserCoupon.deal_user_id' => $id
            ));
            $this->Session->setFlash(__l('Deal User deleted') , 'default', null, 'success');
            $this->redirect(array(
                'action' => 'index'
            ));
        } else {
           $this->Session->setFlash(__l('Deal User delete false') , 'default', null, 'error');
            $this->redirect(array(
                'action' => 'index'
            ));
        }
    }
    
    function admin_index()
    {
        $this->disableCache();
        
        
        $this->paginate = array(
            'conditions' => $conditions,
            'contain' => array(
                'DealUser'=> array(
                    'User.*',
                    'Deal.*',
                    'City.*'
                )
            ) ,
            'order' => array(
                'DealUserVoucher.id' => 'desc'
            ) ,
            'recursive' => 2
        );
        $this->set('dealUserVouchers', $this->paginate());
    }
}
?>